package edu.hawaii.myisern.model;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;

import javax.xml.bind.JAXBException;

import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import edu.hawaii.myisern.researchers.jaxb.Researcher;
import edu.hawaii.myisern.organizations.jaxb.Organization;
import edu.hawaii.myisern.appconfig.jaxb.AppConfig;
import edu.hawaii.myisern.collaborations.jaxb.Collaboration;

/**
 * Test error reports' output.
 *
 * @author Lisa Chen
 */
public class TestReport {

  /** Local instance to test report functions. */
  private Report testReport;

  /**
   * Load the test files every time new test is run.
   *
   * @throws IOException on bad data
   * @throws JAXBException if a parser cannot be created
   */
  @Before
  public void prepareReport() throws JAXBException, IOException {
    // Report test application configuration file
    AppConfig appConfig = IsernManager.loadAppConfig("xml" + File.separatorChar + "examples"
        + File.separatorChar + "appconfig.report.test.xml");
    // load the test files
//    IsernManager.loadApplication();
  }

  /**
   * Test the list of researchers without/invalid organizations error report.
   */
  @Test
  public void testGetResesarchersWithoutOrgs() {
    testReport = new Report();
    List<Researcher> testReportList = new ArrayList<Researcher>();
    testReportList = testReport.getResesarchersWithoutOrgs();
    System.out.println("Researcher errors list size: " + testReportList.size());
    assertEquals("Check if researchers is missing org.", 1, testReportList.size());
  }

  /**
   * Test the list of organizations without/invalid researchers error report.
   */
  @Test
  public void testGetOrgsWithoutResesarchers() {
    testReport = new Report();
    List<Organization> testReportList = new ArrayList<Organization>();
    testReportList = testReport.getOrgsWithoutResesarchers();
    System.out.println("Organizations errors list size: " + testReportList.size());
    assertEquals("Check if org has invalid researcher name.",
        0, testReportList.size());
  }

  /**
   * Test the list of collaborations without/invalid organizations error report.
   */
  @Test
  public void testGetCollabsWithoutOrgs() {
    testReport = new Report();
    List<Collaboration> testReportList = new ArrayList<Collaboration>();
    testReportList = testReport.getCollabsWithoutOrgs();
    System.out.println("Collaborations organizations errors list size: " + testReportList.size());
    assertEquals("Check if collaborations has invalid orgs.",
          1, testReportList.size());
  }

  /**
   * Test the list of collaborations without outcomes error report.
   */
  @Test
  public void testGetCollabsWithoutOutcomes() {
    testReport = new Report();
    List<Collaboration> testReportList = new ArrayList<Collaboration>();
    testReportList = testReport.getCollabsWithoutOutcomes();
    System.out.println("Collaboration outcomes errors list size: " + testReportList.size());
    assertEquals("Check if collaborations is missing a collaboration outcome.",
        1, testReportList.size());
  }

}
